from idlelib.replace import replace
from itertools import count
from os import lstat
from pickletools import string1

# score = [95,36,48,35,100,101]
# new_score = [i if i >=90 else '一般'for i in score ]
# print(new_score)


# a = 0
# n = [95,36,48,35,100,101]
# for i in n:
#     if i % 2 == 0:
#         a += i // 2
#     else:
#         a += i // 2 + 1
# print(f'最少{a}次可以拿完硬币')
#
# lst = [1,5,8,9,45]
# m = len(lst)
# max_val = max(lst)
# min_val = min(lst)
# average_val = sum(lst)/m
#
# print(f"最大值: {max_val}")
# print(f"最小值: {min_val}")
# print(f"平均值: {average_val}")
# print(f"总和: {sum(lst)}")
#
# list1 = [97, 98, 99]
# list2 = [chr(x) for x in list1 ]
# print(list2)
#
# A = [1, 'a', 4, 90]
# B = ['a', 8, 'j', 1]
# C = []
# for  i  in A:
#     for j in  B:
#         if i ==j:
#             C.append(i)
# print(C)

# 获取列表中出现次数最多的元素
# nums = [1, 2, 3, 1, 4, 2, 1, 3, 7, 3, 3]
#
# # from collections import Counter
# # def counter (nums):
# #     return Counter(nums).most_common(1)
# # print(counter(nums)[0][0])
#
# maxTimes = max(nums, key=nums.count)
# print(maxTimes)
#
#
# # 5.获取列表中出现次数最多的元素
# # 例如：nums = [1, 2, 3, 1, 4, 2, 1, 3, 7, 3, 3] — > 打印: 3
#
# # 易错点，当这个列表中，出现最多次数的元素有多个时
# # 第一步：先判断nums这个列表有没有重复的元素
#
# nums = [1, 2, 3, 1, 4, 2, 1, 3, 7, 3, 3, 1]
# unique_nums = []  # nums的去重列表
# max_times = 0  # 初始化最大出现次数
# max_times_element = []
# for i in nums:
#     if i not in unique_nums:
#         unique_nums.append(i)
# if unique_nums != nums:  # 如果它俩不等，代表nums中有重复元素
#     for i in unique_nums:
#         times = 0  # 初始化当前循环的元素出现次数
#         for j in nums:
#             if i == j:
#                 times += 1
#             if times > max_times:
#                 max_times = times
#                 max_times_element = [i]
#             if times == max_times:
#                 if i not in max_times_element:
#                     max_times_element.append(i)
#
#     print(f'最大出现次数的元素是{max_times_element}')



# nums = [1, 2, 3, 1, 4, 2, 1, 3, 7, 3, 3, 1]
# max_times = 0
# max_times_element = []
# for i in nums :
#     times = 0
#     for j in nums:
#         if i == j:
#             times += 1
#         if times > max_times:
#             max_times = times
#             max_times_element = [i]
#         if times == max_times:
#             if i not in max_times_element:
#                 max_times_element.append(i)
# print(f'最大出现次数的元素是{max_times_element}')


# # 目的是找到第一个偶数且大于10的数字
# numbers = [1, 20, 3, 1, 21, 3, 40, 5]
# index_nums = 0
#
# while index_nums<len(numbers):
#     if numbers[index_nums] % 2 ==0 and numbers[index_nums]>10:
#         print(numbers[index_nums])
#         break
#     else:
#         index_nums+=1
# else:
#     print('没有找到')

"""
元组
    1.定义：它是容器序列，可以容纳任何数据类型，表示方法(ele1,ele2,....)单个元素必须(ele1,)
    2.特性：有序不可变，因为有序，可以索引、切片，可遍历，不能增删改
        注意事项：当元组内部有可变元素时，可以对可变元素进行修改
        tup =(1,[1,2,3])
        print(id(tup))
        tup[1][1]=0
        print(id(tup))
    3.常用方法：
        # index(obj) 返回元组中元素的索引号
        # count(obj) 统计某元素在该元组中的出现次数
    4.元组的装包和解包
        装包：就是将多个元素放在一个数据结构中
        解包：提取数据结构中的元素，赋值给一些单独的变量
            # 解包的方式一
            tup = (1, 2, 3, 4)
            tup1 = 1, 23, 4, 5
            # a,b,c,d = tup

            # 解包的方式二
            # print(*tup)

            # 复杂的解包
            tup2 = (1, 2, 4, 5, 6, 7, 8, 8, 9, 45)
            # a,*c,b=tup2
            # print(c)

            # 嵌套的元组
            tup3 = (1, 6, ('a', 'b', 'c'), 7)
            a, b = tup3[:2]
            d = tup3[-1]
            c = tup3[2][0]
            print(a,b,c,d)     
"""""

# print(a,b,c,*d)

# tup = (1, 2, 4, 5, 6, 7, 8, 8, 9, 45)
# count = 0
# for i  in tup:
#     count += 1;
# print(count)

tup = ("alec", " aric", "Alex ", "T on y", "rai n")
new_tup= ()
for i in tup:
    new_tup += (i.replace(" ",""),)
print(new_tup)

tup3 = ("alec", "aric", "Alex", "Tony", "rain")
ls1 = []
for i in tup3:
    if i[0] == ('a' or 'A') and i[-1] == 'c':
        ls1.append(i)
print(tuple(ls1))

# 5.有一个嵌套元组((1, 2), (3, 4), (5, 6))，将其解包成六个单独的变量。
tup4 = ((1, 2), (3, 4), (5, 6))
a, b = tup4[0]
c, d = tup4[1]
e, f = tup4[2]
print(a, b, c, d, e, f)

















